package com.ssy.lingxi.member.merchant.controller.paas;

import com.ssy.lingxi.common.model.vo.PageVO;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.member.merchant.api.model.vo.paas.MemberConfigQueryVO;
import com.ssy.lingxi.member.merchant.api.model.vo.paas.MemberConfigVO;
import com.ssy.lingxi.member.merchant.api.model.vo.paas.MemberRuleFeignVO;
import com.ssy.lingxi.member.merchant.service.paas.IPaasMemberConfigService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 系统初始化 - 会员注册资料配置
 * @author 万宁
 * @date 2020-05-28
 * @version 2.0.0
 */
@RestController
@RequestMapping("/paas/member/detail")
public class MemberConfigController {

    @Resource
    private IPaasMemberConfigService memberConfigService;

    /**
     * 新增会员注册资料
     * @param configVO 接口参数
     * @return 会员资料
     */
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Wrapper<MemberConfigQueryVO> addMemberConfig (@RequestBody @Validated(MemberConfigVO.Add.class) MemberConfigVO configVO) {
        return memberConfigService.addMemberConfig(configVO);
    }

    /**
     * 修改会员资料
     * @param configVO 接口参数
     * @return 会员资料
     */
    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public Wrapper<MemberConfigQueryVO> updateMemberConfig (@RequestBody @Validated(MemberConfigVO.Update.class) MemberConfigVO configVO) {
        return memberConfigService.updateMemberConfig(configVO);
    }

    /**
     * 分页查询会员资料配置
     * @param pageVO 接口参数
     * @return 会员资料
     */
    @RequestMapping(value = "/page", method = RequestMethod.POST)
    public Wrapper<PageData<MemberConfigQueryVO>> pageMemberConfig (@Valid PageVO pageVO) {
        return memberConfigService.pageMemberConfig(pageVO);
    }

    /**
     * 更改会员资料配置状态
     * @param configVO 接口参数
     * @return 会员资料
     */
    @RequestMapping(value = "/status", method = RequestMethod.POST)
    public Wrapper<MemberConfigQueryVO> updateMemberConfigStatus (@RequestBody @Validated(MemberConfigVO.UpdateStatus.class) MemberConfigVO configVO) {
        return memberConfigService.updateMemberConfigStatus(configVO);
    }

    /**
     * 删除会员资料配置状态
     * @param configVO 接口参数
     * @return 操作结果
     */
    @RequestMapping(value = "/delete", method = RequestMethod.POST)
    public Wrapper<Void> deleteMemberConfig (@RequestBody @Validated(MemberConfigVO.Delete.class) MemberConfigVO configVO) {
        return memberConfigService.deleteMemberConfig(configVO);
    }

    /**
     * 新增或修改平台规则配置
     * @param rules 平台规则
     * @return 操作结果
     */
    @RequestMapping(value = "/rules", method = RequestMethod.POST)
    public Wrapper<Void> updateOrInsertMemberRules(@RequestBody List<MemberRuleFeignVO> rules) {
        return memberConfigService.updateOrInsertMemberRules(rules);
    }
}
